using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace VSSDKAssist.Recipes.Common.Helpers
{
	/// <summary>
	/// Common Helper class
	/// </summary>
	public static class CommonHelper
	{
		/// <summary>
		/// Gets the random number.
		/// </summary>
		/// <returns></returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		public static int GetRandomNumber()
		{
			//Sleep to obtain a really random number because of the cpu ticks
			System.Threading.Thread.Sleep(100);
			return new System.Random().Next(System.UInt16.MinValue, System.UInt16.MaxValue); 
		}

		/// <summary>
		/// Gets the vs SDK install path.
		/// </summary>
		/// <returns></returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		public static string GetVSSdkInstallPath()
		{
			using(RegistryKey key = Registry.LocalMachine.OpenSubKey(Constants.VSSdkInstallDirPathKey))
			{
				if(null == key)
					return null;

				return (string)key.GetValue(Constants.VSSdkInstallDirKeyValue);
			}
		}

		/// <summary>
		/// Gets the vs install path.
		/// </summary>
		/// <returns></returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		public static string GetVSInstallPath()
		{
			using(RegistryKey key = Registry.LocalMachine.OpenSubKey(Constants.VSInstallDirPathKey))
			{
				if(null == key)
					return null;

				return (string)key.GetValue(Constants.VSInstallDirKeyValue);
			}
		}
	}
}